<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <jsp:include page="/WEB-INF/jsp/include/headBase.jsp"/>
</head>
<body style="padding-left: 40px">
<br>
<br>
<div>
    <form id="form_businessInfo" class="form-horizontal row">
        <div class="col-sm-10" id="div-error"></div>
        <input type="hidden" name="managerUserId" value="${managerUserId}">
        <input type="hidden" name="observerUserId" value="">
        <input type="hidden" name="itemNum" value="${itemNum}" >

        <div class="form-group col-sm-3">
            <label class="control-label col-sm-4">单位名称：</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="companyName" value="${companyName}" readonly>
            </div>
        </div>

        <div class="form-group col-sm-3">
            <label class="control-label col-sm-4">单位代码：</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="companyCode" readonly value="${companyCode}">
            </div>
        </div>

        <div class="form-group col-sm-3">
            <label class="control-label col-sm-4">业务类型：</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="businessType" value="${businessType}" readonly>
            </div>
        </div>

        <div class="form-group col-sm-3">
            <label class="control-label col-sm-4">业务号：</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="businessCode" value="${businessCode}" readonly>
            </div>
        </div>

        <div class="form-group col-sm-3">
            <label class="col-sm-4 control-label">申请日期：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="applicationTime" value="${applicationTime}" readonly>
            </div>
        </div>

        <div class="form-group col-sm-3">
            <label class="col-sm-4 control-label">受理日期：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="acceptTime" value="${acceptTime}" readonly>
            </div>
        </div>

        <div class="form-group col-sm-3">
            <label class="control-label col-sm-4">核查地址：</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="address" value="${address}" readonly>
            </div>
        </div>

        <div class="form-group col-sm-3">
            <label class="control-label col-sm-4">专业：</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="oldMajor" value="${oldMajor}" readonly>
            </div>
        </div>

        <div class="form-group col-sm-6">
            <label class="control-label col-sm-2">专业树：</label>
            <div class="col-sm-10">
                <div class="form-control-free" style=" overflow:auto;  max-height:550px; padding-left: 100px">
                    <ul id="treeDemo1" class="ztree"></ul>
                </div>
            </div>
        </div>

        <div class="form-group  col-sm-3">
            <div class="form-control-free" style=" overflow:auto;  height:365px;">
                <ul id="log" class="log"></ul>
                <input type="hidden" name="hidden_log" id="hidden_log">
            </div>
        </div>

        <div class="form-group  col-sm-3">
            <div class="col-sm-8 col-sm-offset-4">
                <button type="submit" class="btn btn-default btn-success">
                    <span class="glyphicon glyphicon-ok"></span>&nbsp;提交&nbsp;
                </button>
            </div>
        </div>
    </form>


</div>
<jsp:include page="/WEB-INF/jsp/include/footerBase.jsp"/>
<script>
    var $form = $("#form_businessInfo");
    $(function () {
        <%--bootstrapValidator--%>

        $form.bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            excluded: [],
            fields: {
                hidden_log: {
                    validators: {
                        notEmpty: {
                            message: '不能为空!'
                        }
                    }
                }
            }
        }).on('success.form.bv', function (e) {
            e.preventDefault();

            var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
            var nodes = treeObj.getCheckedNodes(true);

            var ids = new Array();
            for (var i = 0; i < nodes.length; i++) {
                if (!nodes[i].isParent)
                    ids.push(nodes[i].data);
            }
            if (ids.length == 0) {
                alert("专业不能为空");
                return;
            }
            var data = $(e.target).serializeObject();
            data['majorNumList'] = ids.toString();
            var url, operateType;

            $.sysPlugin.superAjax({
                data: data,
                url: "${base}/httpPage/addBusiness",
                operateType: 'insert',
                showSuccessAlert: true,
                showWarnAlert: true,
                successCall: function (data) {
                    window.location.reload();
                },
                errorCall: function (data) {
                    $.sysPlugin.errorCallBack(data, {
                        errorAddress: $("#div-error"),
                        form: $form
                    })
                }, warnAlertCancelCall: function () {
                    $form.data('bootstrapValidator').resetForm();
                }
            });
        });
        $.sysPlugin.initSimpleSelect2();
        $.sysPlugin.initDateTimeInput();
    });
</script>


<script>


    var setting = {
        async: {
            enable: true,
            url: "${base}/httpPage/getProfessionTree"
        },
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }, callback: {
            onAsyncSuccess: function (event, treeId, treeNode, msg) {
                var treeObj = $.fn.zTree.getZTreeObj(treeId);
                $.each(treeObj.getNodes(), function (i, v) {
                    treeObj.expandNode(v, true, false, true);
                })
            },
            beforeCheck: beforeCheck,
            onCheck: onCheck
        }
    };

    function beforeCheck(treeId, treeNode) {
        clearLog();
        return null;
    }

    function onCheck(e, treeId, treeNode) {
        var nodes = zTree.getCheckedNodes(true);
        nodes.length == 0 ? hiddenLog.val("") : hiddenLog.val("。");
        $form.bootstrapValidator('revalidateField', "hidden_log");

        for (var i = 0, l = nodes.length; i < l; i++) {
            if (nodes[i].isParent) {
                continue;
            } else {
                showLog(nodes[i].name)
            }
        }

    }

    var log, zTree, hiddenLog = $("#hidden_log");

    function showLog(str) {
        if (!log) log = $("#log");
        log.append("<li class='dark'>" + str + "</li>");
    }

    function clearLog() {
        if (!log) log = $("#log");
        log.html("");
    }

    $(function () {
        $.fn.zTree.init($("#treeDemo1"), setting);
        if (!zTree) zTree = $.fn.zTree.getZTreeObj("treeDemo1");

    });

</script>

</body>
</html>